package com.zys.sac.core.handler;

import com.zys.sac.core.constant.RequestStatus;
import com.zys.sac.core.util.ServletResponseUtils;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 异常处理类，发生异常时会调用
 *
 * Created by zhongjunkai on 2022/3/11.
 */
public class SacAuthenticationEntryPoint implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
        ServletResponseUtils.render(httpServletResponse, ServletResponseUtils.result(RequestStatus.FAILURE.getCode(), RequestStatus.FAILURE.getMsg()));
    }
}
